var a = getApp();

Page({
    data: {
        selected: "0",
        pagesize: 1,
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        love_name: "",
        usable: 0,
        allData: [],
        incomeData: [],
        expendData: [],
        loveLang: {}
    },
    onLoad: function(a) {
        try {
            var t = wx.getStorageSync("yz_basic_info");
            t.lang.love && this.setData({
                loveLang: t.lang.love
            });
        } catch (a) {
            console.log(a);
        }
        this.setData({
            selected: "0"
        }), this.initData(), this.getUsable(), this.getNetData(0);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.loadBottom();
    },
    onShareAppMessage: function() {},
    getUsable: function() {
        var t = this, e = a.getNetAddresss("plugin.love.Frontend.Controllers.page.index");
        a._getNetWork({
            url: e,
            success: function(a) {
                1 === a.data.result ? t.setData({
                    usable: a.data.data.usable,
                    love_name: a.data.data.love_name
                }) : wx.showToast({
                    title: a.data.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    initData: function() {
        this.data.page = 1, this.data.total_page = 0, this.data.goload = !0, this.data.loading = !0, 
        this.data.allLoaded = !1, this.data.isLoadMore = !0, this.data.allData = [], this.data.incomeData = [], 
        this.data.expendData = [];
    },
    onChange: function(a) {
        this.initData(), this.data.selected = a.detail.index, console.log(a), this.getNetData(a.detail.index);
    },
    loadBottom: function() {
        this.data.isLoadMore ? this.getMoreData(this.data.page, this.data.selected) : console.log("没有更多数据");
    },
    switchItem: function() {
        this.getNetData(this.data.selected);
    },
    getNetData: function(t) {
        var e = this, o = a.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.love-records.index");
        o += "&service_type=" + t, o += "&page=1", a._getNetWork({
            url: o,
            success: function(a) {
                if (1 === a.data.result) {
                    var o = a.data.data;
                    e.setData({
                        total_page: a.data.data.last_page
                    }), 0 == t ? e.setData({
                        incomeData: [],
                        expendData: [],
                        allData: o.data
                    }) : 1 == t ? e.setData({
                        incomeData: o.data,
                        expendData: [],
                        allData: []
                    }) : 2 == t && e.setData({
                        incomeData: [],
                        expendData: o.data,
                        allData: []
                    });
                } else wx.showToast({
                    title: a.data.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getMoreData: function(t, e) {
        var o = this;
        if (this.data.page != this.data.total_page) if (this.data.page >= this.data.total_page) this.setData({
            loading: !0,
            allLoaded: !0
        }); else {
            this.setData({
                page: this.data.page + 1
            });
            var s = a.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.love-records.index");
            s += "&service_type=" + e, s += "&page=" + this.data.page, a._getNetWork({
                url: s,
                success: function(a) {
                    if (1 == a.data.result) {
                        var t = a.data.data;
                        if (o.setData({
                            loading: !1,
                            allLoaded: !1
                        }), 0 == e) {
                            var s = o.data.allData.concat(t.data);
                            o.setData({
                                allData: s
                            });
                        } else if (1 == e) {
                            var n = o.data.incomeData.concat(t.data);
                            o.setData({
                                incomeData: n
                            });
                        } else if (2 == e) {
                            var i = o.data.expendData.concat(t.data);
                            o.setData({
                                expendData: i
                            });
                        }
                    } else {
                        var l = o.data.page - 1;
                        o.setData({
                            page: l,
                            loading: !0,
                            allLoaded: !0,
                            isLoadMore: !1
                        });
                    }
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        } else this.setData({
            isLoadMore: !1
        });
    }
});